package com.byapp.fast.common.converter;

import com.byapp.fast.modules.match.dto.MatchDetailDTO;
import com.byapp.fast.modules.match.entity.MatchRefEntity;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

public class MatchDetailDTOConverter implements ConverterFactory<MatchDetailDTO,MatchRefEntity> {

    private MatchDetailDTOConverter() {
    }

    @Override
    public MatchDetailDTO create(MatchRefEntity matchRefEntity) {
        return new MatchDetailDTO()
                .setGtLogo(matchRefEntity.getHomeTeamLogo())
                .setGtName(matchRefEntity.getHomeTeamName())
                .setHtLogo(matchRefEntity.getAwayTeamLogo())
                .setHtName(matchRefEntity.getAwayTeamName())
                .setLeagueId(matchRefEntity.getLeagueId())
                .setLeagueName(matchRefEntity.getLeagueName())
                .setMatchId(matchRefEntity.getMatchId())
                .setMatchTime(matchRefEntity.getMatchTime())
                ;
    }


    public static List<MatchDetailDTO> mapToTarget(List<MatchRefEntity> list) {
        return !CollectionUtils.isEmpty(list) ? list.stream()
                .map(new MatchDetailDTOConverter()::create)
                .collect(Collectors.toList()) : null;
    }

}
